package io.zhifei.modules.sys.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.*;
import io.zhifei.common.utils.PageUtils;
import io.zhifei.common.utils.R;
import io.zhifei.modules.app.login.entity.Banner;
import io.zhifei.modules.sys.system.form.BannerParam;
import io.zhifei.modules.sys.system.form.BannerResult;
import io.zhifei.modules.sys.system.service.BannerService;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;


/**
 * banner控制器
 *
 * @author duke
 * @Date 2021-05-21 09:35:52
 */
@RestController
@RequestMapping("/banner")
@Api(value = "banner管理",tags = "banner管理")
public class BannerController{

    @Resource
    private BannerService bannerService;


    /**
     * 新增接口
     *
     * @author duke
     * @Date 2021-05-21
     */
    @PutMapping("/addItem")
    @ApiOperation(value = "新增banner",httpMethod = "PUT")
    public R addItem(BannerParam bannerParam) {
        this.bannerService.add(bannerParam);
        return R.ok();
    }

    /**
     * 编辑接口
     *
     * @author duke
     * @Date 2021-05-21
     */
    @PostMapping("/editItem")
    @ApiOperation(value = "修改banner",httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "主键", name = "id", required = true),
            @ApiImplicitParam(value = "图片地址", name = "imgPath"),
            @ApiImplicitParam(value = "所属页面，homePage：首页，aboutPage：关于我们", name = "genus")
    })
    public R editItem(@ApiIgnore BannerParam bannerParam) {
        this.bannerService.update(bannerParam);
        return R.ok();
    }

    /**
     * 删除接口
     *
     * @author duke
     * @Date 2021-05-21
     */
    @DeleteMapping("/delete")
    @ApiOperation(value = "删除banner",httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "主键", name = "id", required = true)
    })
    public R delete(@ApiIgnore BannerParam bannerParam) {
        bannerParam.setFlag(1);
        this.bannerService.update(bannerParam);
        return R.ok();
    }

    /**
     * 查看详情接口
     *
     * @author duke
     * @Date 2021-05-21
     */
    @GetMapping("/getDetail")
    @ApiOperation(value = "查看详情",httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "主键", name = "id", required = true)
    })
    @ApiResponse(code = 200,message = "请求成功",response = BannerResult.class)
    public R detail(@ApiIgnore BannerParam bannerParam) {
        Banner detail = this.bannerService.getById(bannerParam.getId());
        return R.ok().put("data",detail);
    }

    /**
     * 查询列表
     *
     * @author duke
     * @Date 2021-05-21
     */
    @ApiOperation(value = "查询分页列表")
    @GetMapping("/getPageList")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页", required = true),
            @ApiImplicitParam(name = "pageSize", value = "当前页大小", required = true)
    })
    @ApiResponse(code = 200,message = "请求成功",response = BannerResult.class)
    public R list(@ApiIgnore Integer page, @ApiIgnore Integer pageSize,@ApiIgnore BannerParam bannerParam) {
        PageUtils pageList = this.bannerService.findPageBySpec(new Page(page,pageSize),bannerParam);
        return R.ok().put("data",pageList);
    }

}


